package com.fuxi.cloud.desreport.render.utils;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.fuxi.cloud.desreport.render.b.b;

import java.util.*;

/**
 * ReportUtil
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */
public class ReportUtil {
    public ReportUtil() {
    }

    public static List<b> a(JSONObject var0) {
        LinkedList var1 = new LinkedList();
        Iterator var2 = var0.entrySet().iterator();

        while(var2.hasNext()) {
            Map.Entry var3 = (Map.Entry)var2.next();
            Object var4 = var3.getValue();
            Object var5 = var3.getKey();
            if (var4 instanceof JSONObject) {
                List var6 = a((JSONObject)var4, var5);
                if (ObjectUtil.isNotEmpty(var6)) {
                    var1.addAll(var6);
                }
            }
        }

        return var1;
    }

    public static List<b> a(JSONObject var0, Object var1) {
        LinkedList var2 = new LinkedList();
        JSONObject var3 = var0.getJSONObject("cells");
        if (var3 instanceof JSONObject) {
            Iterator var4 = var3.entrySet().iterator();

            while(true) {
                String var7;
                String var8;
                Boolean var9;
                Boolean var10;
                do {
                    do {
                        do {
                            if (!var4.hasNext()) {
                                return var2;
                            }

                            Map.Entry var5 = (Map.Entry)var4.next();
                            JSONObject var6 = (JSONObject)var5.getValue();
                            var7 = var6.getString("text");
                        } while(!ObjectUtil.isNotEmpty(var7));

                        var8 = RegexMatches.a(var7, 2);
                    } while(!ObjectUtil.isNotEmpty(var8));

                    var9 = var8.indexOf("groupRight(") != -1;
                    var10 = var8.indexOf("group(") != -1;
                } while(!var9 && !var10);

                b var11 = new b();
                String var12 = RegexMatches.b(var8, 2).replace(")", "");
                String var13 = var7.substring(var7.lastIndexOf("}") + 1);
                var11.setColumn(var12);
                var11.setSuffixText(var13);
                if (var10) {
                    var11.setDirection("up");
                } else {
                    var11.setDirection("right");
                }

                var11.setRow(var0);
                var11.setRowKey(var1.toString());
                var2.add(var11);
            }
        } else {
            return var2;
        }
    }

    public static Boolean a(String var0, List<b> var1) {
        Iterator var2 = var1.iterator();

        String var4;
        do {
            if (!var2.hasNext()) {
                return false;
            }

            b var3 = (b)var2.next();
            var4 = var3.getColumn();
        } while(!var4.equals(var0));

        return true;
    }

    public static List<Map<String, Object>> a(List<Map<String, Object>> var0) {
        ArrayList var1 = new ArrayList();
        if (ObjectUtil.isNotEmpty(var0)) {
            Iterator var2 = var0.iterator();

            while(var2.hasNext()) {
                Map<String,Object> var3 = (Map)var2.next();
                JSONObject var4 = new JSONObject();
                var3.forEach((var1x, var2x) -> {
                    if (ObjectUtil.isNotEmpty(var2x)) {
                        var4.put(var1x.toLowerCase(), var2x.toString());
                    } else {
                        var4.put(var1x.toLowerCase(), "");
                    }

                });
                var1.add(var4);
            }
        }

        return var1;
    }

    public static void main(String[] args) {
    }
}

